package org.yellow.backend.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yellow.backend.pojo.medicine;
import org.yellow.backend.service.medicineService;

import java.util.List;

/**
 * @author: hy
 * @create: 2024-01-01
 */
@RestController
@CrossOrigin
@SuppressWarnings({"all"})
@RequestMapping("/medicine")
public class medicineController {
    @Autowired
    private medicineService service;
    @GetMapping("/{id}")
    public medicine getMedicine(@PathVariable("id") int id){
        return service.selectMedicineById(id);
    }
    @PutMapping("/updateStock/{volume}/{medicineName}")
    public boolean decreaseStock(@PathVariable("volume") int volume,@PathVariable("medicineName") String medicineName){
        System.out.println("volume==>"+volume);
        System.out.println("medicineName===>"+medicineName);
        return service.decreaseStock(volume,medicineName);
    }
    @GetMapping("/getStock/{name}")
    public Long selectStock(@PathVariable String name){
        return service.selectStock(name);
    }

    @GetMapping("/getAll")
    public List<medicine> getAll(){
        return service.getAll();
    }
}
